package com.example.order.controller;

import com.example.order.service.InventoryApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OrderController {

  @Autowired private InventoryApiService inventoryApiService;

  /**
   * 没有网关的时候 :去这里请求就可以
   * http://localhost:9090/create?productId=1&userId=10086&count=10&totalPrice=1000
   *
   * @param productId 商品ID
   * @param userId 用户ID
   * @param count 购买数量
   * @param totalPrice 增加多少积分
   * @return
   */
  @GetMapping("/create")
  public String greeting(
      @RequestParam("productId") Long productId,
      @RequestParam("userId") Long userId,
      @RequestParam("count") Long count,
      @RequestParam("totalPrice") Long totalPrice) {
    System.out.println("创建订单:购买商品ID"+productId+" 的商品"+count+"件");
    String s = inventoryApiService.deductStock(productId, count);
    System.out.println("库存微服务返回:"+s);
    // wmsService.delivery(productId);
    // creditService.add(userId, totalPrice);
    return "订单创建返回"+s;
  }
}
